package mybatis.main;

import static java.lang.System.out;

import java.io.Reader;
import java.sql.Date;

import mybatis.domain.User;
import mybatis.mapper.Mapper09;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

//mapper09.xml, SqlMapConfig.xml
public class Main09 {	
	public static void main(String[] args) throws Exception{		
		Reader reader = Resources.getResourceAsReader("config/SqlMapConfig.xml");		
		SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);		
		SqlSession sqlSession = sqlSessionFactory.openSession();
		
		Mapper09 mapper = sqlSession.getMapper(Mapper09.class);
		
		out.println("[addUser]");
		mapper.addUser(new User("u21","u21","박나린",33,Date.valueOf("2014-02-18")));
		
		out.println("[getUser]");
		out.println(mapper.getUser("u21"));
		
		out.println("[updateUser]");
		mapper.updateUser(new User("u21",null,"박수정",23,null));
		
		out.println("[getUser]");
		out.println(mapper.getUser("u21"));
		
		out.println("[delUser]");
		mapper.delUser("u21");
		
		sqlSession.commit();
		
		out.println("[getUsers]");
		for(User user:mapper.getUsers())
			out.println(user);
	}
}